#include <iostream>
#include <queue>
using namespace std;

const int kMaxY = 1e5 + 10;

int dis[kMaxY * 2];

int BFS(int x, int y) {
  queue<int> que;

  if (x > y) {
    return x - y;
  }
  fill(dis, dis + 2 * y + 10, 0);
  dis[0] = 1;
  dis[x] = 1;
  que.emplace(x);
  while (!que.empty() && dis[y] == 0) {
    int now = que.front();

    que.pop();
    if (dis[now + 1] == 0) {
      que.emplace(now + 1);
      dis[now + 1] = dis[now] + 1;
    }
    if (dis[now - 1] == 0) {
      que.emplace(now - 1);
      dis[now - 1] = dis[now] + 1;
    }
    if (now < y && dis[now * 2] == 0) {
      dis[now * 2] = dis[now] + 1;
      que.emplace(now * 2);
    }
  }
  return dis[y] - 1;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;
  for (cin >> T; T; T--) {
    int x, y;

    cin >> x >> y;
    cout << BFS(x, y) << "\n";
  }
  return 0;
}
